<template>
  <div o-Container>
    <!-- created: create, -->
    <!-- v-bind="{ exported: output }" -->
    <div class="top_box">
      <div class="search_box">
        <img src="/static/skin/herodoo/main/platform/home/img/search.png" alt="" />
        <input :value="searchValue" type="text" placeholder="请输入搜索内容" @keydown.enter="searchEnterKeyPress"
          @blur="searchEnterKeyPress" />
        <img @click="fdrawerOp()" src="/static/skin/herodoo/main/platform/home/img/shaixuan.png" alt="" />
      </div>
    </div>
    <o-list v-bind:source="list.contract">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img @click="showLookDiaolog(scope)" src="/static/skin/default/MCS/AIGC/Inventory/images/chakan.png" alt="" />
          <img @click="showEditDialog(scope)" src="/static/skin/default/MCS/AIGC/Inventory/images/bianji.png" alt="" />
          <!-- <img src="/static/skin/default/MCS/AIGC/Inventory/images/shanchu.png" alt=""> -->
        </div>
      </template>
    </o-list>
    <lookDiaolog ref="lookDiaolog" :messageList="messageList"></lookDiaolog>
    <editDialog ref="editDialog" :messageList="messageListAdd" @reload="reload"></editDialog>
    <!-- 精细化筛选 -->
    <screenRights @searchFun="search" ref="screenRights"></screenRights>
  </div>
</template>

<script>
import lookDiaolog from "../Components/lookDialog.vue";
import editDialog from "../Components/editDialog.vue";
import screenRights from "../Components/screenRights.vue";
export default {
  components: {
    lookDiaolog,
    editDialog,
    screenRights
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1195, // 菜单表的八爪鱼ID
            cellData: [
              { name: "Name", width: 200 }, // 权益标题
              { name: "CompanyID", show: false }, // 提交企业
              { name: "CompanyName" }, // 提交企业
              { name: "TypeID", show: false }, // 是否为权益礼包
              { name: "TypeIDName" }, // 是否为权益礼包
              { name: "EquityListCount" }, // 权益数量
              { name: "Status", show: false, filterKey: 'in', filterValue: [5, 6, 7, 8, 9, 10] }, // 审核状态
              { name: "StatusName" }, // 审核状态
              { name: "SalePrice" }, // 市场价格
              { name: "PlatformServiceRate" }, // 平台服务费
              { name: "EquityServiceRate" }, // 小程序服务费
              { name: "CostPrice" }, // 平台价格
              { name: "Integral" }, // 让利积分
              { name: "PlatformServicePrice" }, // 平台结算价格（元）
              { name: "EquityServicePrice" }, // 小程序结算价格（元）
              { name: "Visits" }, // 访问量
              { name: "InventoryQuantity" }, // 库存数量(份)
              { name: "SoldQuantity" }, // 总销量
              { name: "PlatformStatus", show: false }, // 平台状态
              { name: "PlatformStatusName" }, // 平台状态
              { name: "PlatformShelfTime", width: 150 }, // 权益平台上架时间
              { name: "PlatformSoldQuantity" }, // 权益平台销售数量
              { name: "EquityStatus", show: false }, // 小程序状态
              { name: "EquityStatusName" }, // 小程序状态
              { name: "EquityShelfTime" }, // 小程序上架时间
              { name: "EquitySoldQuantity" }, // 小程序销售数量
              { name: "CreateTime", width: 150 }, // 提交时间
              { name: "EquityFlagList", show: false }, // 权益标签
              { name: "TransferRuleID", show: false } // 采购公司限制
            ],
            paramData: {}
          },
          // 筛选内容
          searchValue: "",
          // 权益标签
          labelID: [],
          // 权益类型
          typeID: [],
          // 价格
          priceArr: "",
          // 公司限制
          company: [],
          // 时间
          dateData: [],
          // 审核状态
          statusDtata: [],
          configWidth: 60,
          showNumber: true
        }
      },
      repetition: true,
      messageList: {},
      messageListAdd: {},
      rightList: [],
      searchValue: ""
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      const data = this.list.contract.data;
      let company = this.octopus.passport.authorization.company;
      data.paramData.CompanyID = company == 1 ? "NULL" : company;
    },
    showLookDiaolog(row) {
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1195,
          cellData: [
            { name: "Address" }, // 使用地址
            { name: "CompanyID" }, // 提交企业
            { name: "CompanyName" }, // 提交企业
            { name: "CostPrice" }, // 平台价格
            { name: "CreateTime" }, // 提交时间
            { name: "Description" }, // 权益详情
            { name: "EffectiveTime" }, // 生效时间
            { name: "EquityFlagList" }, // 权益标签
            { name: "EquityFlagListName" }, // 权益标签
            { name: "EquityList" }, // 权益集合
            { name: "EquityListCount" }, // 权益数量
            { name: "EquityServicePrice" }, // 小程序结算价格（元）
            { name: "EquityServiceRate" }, // 权益平台服务费
            { name: "EquityShelfTime" }, // 小程序上架时间
            { name: "EquityStatus" }, // 小程序状态
            { name: "ExpireTime" }, // 过期时间
            { name: "FilePath" }, // 合同附件路径
            { name: "ID", filterKey: "=", filterValue: row.data.row.ID }, // ID
            { name: "Integral" }, // 让利积分
            { name: "InventoryQuantity" }, // 库存数量(份)
            { name: "IsOpenSale" }, // 是否允许在其他国企平台售卖
            { name: "IsRealNameAuthentication" }, // 是否需要实名信息
            { name: "IsRefund" }, // 是否允许退款
            { name: "IsRefundAudit" }, // 是否需要退款审核
            { name: "MainPicturePath" }, // 主图
            { name: "MinimumQuantity" }, // 起售数量
            { name: "Name" }, // 权益标题
            { name: "PlatformServicePrice" }, // 平台结算价格（元）
            { name: "PlatformServiceRate" }, // 平台服务费
            { name: "PlatformShelfTime" }, // 权益平台上架时间
            { name: "PlatformStatus" }, // 平台状态
            { name: "ProductCode" }, // 合同编号
            { name: "ProductFlagList" }, // 产品类型
            { name: "ProductFlagListName" }, // 产品类型
            { name: "ProductID" }, // 产品ID
            { name: "SalePrice" }, // 市场价格
            { name: "SecondaryPicturePath" }, // 副图
            { name: "SoldQuantity" }, // 总销量
            { name: "Status" }, // 审核状态
            { name: "StatusName" }, // 审核状态
            { name: "TransferRuleID" }, // 采购公司限制
            { name: "TransferRuleIDName" }, // 采购公司限制
            { name: "TypeID" }, // 是否为权益礼包
            { name: "UsersCount" }, // 使用人数
            { name: "UseRuleDescription" }, // 使用规则详情
            { name: "Visits" }, // 访问量
            { name: "PlatformSoldQuantity" }, // 权益平台销售数量
            { name: "EquitySoldQuantity" }, // 小程序销售数量
            { name: "IsRefund" }, // 是否允许退款
            { name: "IsRefundAudit" } // 退款是否需要审核
          ],
          paramData: {
            CompanyID:
              this.octopus.passport.authorization.company == 1
                ? "NULL"
                : this.octopus.passport.authorization.company
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.messageList = data.content.queryData[0];
            o.$refs.lookDiaolog.drawerOp();
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    showEditDialog(row) {
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1195,
          cellData: [
            { name: "ID", filterKey: "=", filterValue: row.data.row.ID }, //ID
            { name: "Name" }, // 权益标题
            { name: "InventoryQuantity" }, // 库存数量(份)
            { name: "CompanyID" }, // 库存数量(份)
            { name: "TypeID" } // 是否为权益礼包
          ],
          paramData: {
            CompanyID:
              this.octopus.passport.authorization.company == 1
                ? "NULL"
                : this.octopus.passport.authorization.company
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.messageListAdd = data.content.queryData[0];
            o.$refs.editDialog.drawerOp();
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // showLookDiaolog() {
    //   this.$refs.lookDiaolog.drawerOp()
    // },
    output: function (data) {
      this.octopus.tips.success("下载完成。");
    },
    // 精细化查询
    search(labelID, typeID, priceArr, company, dateData, statusDtata) {

      this.labelID = labelID;
      this.typeID = typeID;
      this.priceArr = priceArr;
      this.company = company;
      this.dateData = dateData;
      this.statusDtata = statusDtata;
      const data = this.list.contract.data.cellData;
      data.map(item => {
        if (item.name == "CostPrice") {
          (item.filterKey = "BETWEEN"), (item.filterValue = this.priceArr);
        }
        if (item.name == "EquityFlagList") {
          (item.filterKey = "LIKE"), (item.filterValue = this.labelID.join());
        }
        if (item.name == "Name") {
          (item.filterKey = "LIKE"), (item.filterValue = this.searchValue);
        }
        if (item.name == "TypeID") {
          (item.filterKey = "IN"), (item.filterValue = this.typeID);
        }
        if (item.name == "TransferRuleID") {
          (item.filterKey = "LIKE"), (item.filterValue = this.company.join());
        }
        if (item.name == "Status") {
          (item.filterKey = "IN"), (item.filterValue = this.statusDtata);
        }
      });
      this.list.contract.control.load();
    },

    searchEnterKeyPress(e) {
      if (e.target.value == this.searchValue) {
        return;
      }
      this.searchValue = e.target.value;
      const cellData = this.list.contract.data.cellData;
      // 遍历 cellData，找到符合条件的元素，并添加键值对
      cellData.forEach(item => {
        if (item.name === "Name") {
          // 添加 filterKey 和 filterValue
          item.searchKey = "like";
          item.searchValue = this.searchValue;
        }
      });
      this.list.contract.control.load();
    },
    fdrawerOp() {
      this.$refs.screenRights.drawerOp();
    },
    reload() {
      this.list.contract.control.load();
    }
  },
  props: ["oData"]
};
</script>
<style scoped>
.top_box {
  width: 100%;
  height: 5.3rem;
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  padding-bottom: 1.2rem;
  box-sizing: border-box;
}

.top_box .search_box {
  width: 32rem;
  height: 100%;
  border: 1px solid #f0f0f0;
  border-radius: 4rem;
  display: flex;
  justify-content: space-between;
  padding: 0 0.8rem;
  box-sizing: border-box;
}

.top_box .search_box input {
  border: none;
  outline: none;
  width: 70%;
}

.top_box .search_box img {
  cursor: pointer;
}

.top_box .button_box button {
  width: 15rem;
  height: 100%;
  border-radius: 4rem;
  border: none;
  color: #fff;
  background-color: #f78c52;
  box-shadow: 0px -3px 4px 0px rgba(204, 190, 186, 0.4);
  font-size: 1.7rem;
  cursor: pointer;
}

.top_box .button_box button {
  margin-right: 1.3rem;
}

.el-message-box {
  background-color: #fff !important;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}

>>>.Content {
  height: 84vh !important;
}
</style>
